package com.jd.sunny.java.annotation;


import java.lang.reflect.Method;

/**
 * Created by IntelliJ IDEA. User: sunlin Date: 12-8-10 Time: 涓嬪�?:17 To change
 * this template use File | Settings | File Templates.
 */
public class Test {
    /*
      * 琚敞瑙ｇ殑涓変釜鏂规硶
      */
    @MyAnotation(id = 1, description = "hello method_1")
    public void method_1() {
    }

    @MyAnotation(id = 2)
    public void method_2() {
    }

    @MyAnotation(id = 3, description = "last method")
    public void method_3() {
    }

    /*
      * 瑙ｆ瀽娉ㄨВ锛屽皢Test_1绫�鎵�湁琚敞瑙ｆ柟娉�鐨勪俊鎭墦鍗板嚭鏉�
      */
    public static void main(String[] args) {
        Method[] methods = Test.class.getDeclaredMethods();
        for (Method method : methods) {
            /*
                * 鍒ゆ柇鏂规硶涓槸鍚︽湁鎸囧畾娉ㄨВ绫诲�?鐨勬敞瑙�?
                */
            boolean hasAnnotation = method
                    .isAnnotationPresent(MyAnotation.class);
            if (hasAnnotation) {
                /*
                     * 鏍规嵁娉ㄨВ绫诲�?杩斿洖鏂规硶鐨勬寚�?氱被鍨嬫敞瑙�?
                     */
                MyAnotation annotation = method
                        .getAnnotation(MyAnotation.class);
                System.out.println("Test( method = " + method.getName()
                        + " , id = " + annotation.id() + " , description = "
                        + annotation.description() + " )");
            }
        }
    }

}
